---
// SEO结构化数据组件
// 用于添加JSON-LD结构化数据，提升搜索引擎理解

interface Props {
  type?: 'website' | 'organization' | 'article' | 'product';
  title?: string;
  description?: string;
  url?: string;
  image?: string;
  organizationName?: string;
  articleAuthor?: string;
  articlePublishedTime?: string;
  articleModifiedTime?: string;
  productName?: string;
  productPrice?: string;
  productCurrency?: string;
}

const {
  type = 'website',
  title,
  description,
  url,
  image,
  organizationName = '172号卡官网',
  articleAuthor,
  articlePublishedTime,
  articleModifiedTime,
  productName,
  productPrice,
  productCurrency = 'CNY'
} = Astro.props;

// 基础组织信息
const organizationSchema = {
  "@context": "https://schema.org",
  "@type": "Organization",
  "name": organizationName,
  "url": "https://urlka.cn",
  "logo": "https://urlka.cn/assets/logo/logo.png",
  "description": "172号卡官网！我们提供最新的电信、移动、联通和广电流量卡及物联卡的在线申请和办理服务",
  "contactPoint": {
    "@type": "ContactPoint",
    "telephone": "+86-400-000-0000",
    "contactType": "customer service",
    "availableLanguage": "Chinese"
  },
  "sameAs": [
    "https://weibo.com/172hk",
    "https://space.bilibili.com/172hk"
  ]
};

// 网站信息
const websiteSchema = {
  "@context": "https://schema.org",
  "@type": "WebSite",
  "name": title || "172号卡分销系统官网",
  "url": url || "https://urlka.cn",
  "description": description,
  "publisher": organizationSchema,
  "potentialAction": {
    "@type": "SearchAction",
    "target": "https://urlka.cn/search?q={search_term_string}",
    "query-input": "required name=search_term_string"
  }
};

// 文章信息
const articleSchema = type === 'article' ? {
  "@context": "https://schema.org",
  "@type": "Article",
  "headline": title,
  "description": description,
  "image": image,
  "author": {
    "@type": "Person",
    "name": articleAuthor || "172号卡编辑部"
  },
  "publisher": organizationSchema,
  "datePublished": articlePublishedTime,
  "dateModified": articleModifiedTime || articlePublishedTime,
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": url
  }
} : null;

// 产品信息
const productSchema = type === 'product' ? {
  "@context": "https://schema.org",
  "@type": "Product",
  "name": productName || title,
  "description": description,
  "image": image,
  "brand": {
    "@type": "Brand",
    "name": organizationName
  },
  "offers": {
    "@type": "Offer",
    "price": productPrice,
    "priceCurrency": productCurrency,
    "availability": "https://schema.org/InStock",
    "seller": organizationSchema
  }
} : null;

// 根据类型选择合适的schema
let schema;
switch (type) {
  case 'article':
    schema = articleSchema;
    break;
  case 'product':
    schema = productSchema;
    break;
  case 'organization':
    schema = organizationSchema;
    break;
  default:
    schema = websiteSchema;
}
---

<!-- 结构化数据 JSON-LD -->
<script type="application/ld+json" set:html={JSON.stringify(schema)} />

<!-- 如果是首页，同时添加组织信息 -->
{type === 'website' && (
  <script type="application/ld+json" set:html={JSON.stringify(organizationSchema)} />
)}